<template>
  <div class="demo">
    <ToolBar>
      <el-button type="primary" icon="el-icon-plus" size="small" @click="addTeacher()">添加讲师</el-button>
      <div style="float: right">
        <el-input
                placeholder="搜索"
                size="small"
                style="width: 140px"
                v-model="searchParams.name"
                clearable>
        </el-input>
        <el-button type="success" icon="el-icon-search" size="small" @click="getList()"></el-button>
      </div>
    </ToolBar>
    <el-table
            :data="tableData"
            border
            style="width: 100%">
      <el-table-column
              prop="id"
              label="id"
              width="180">
      </el-table-column>
      <el-table-column
              prop="name"
              label="名称"
              width="180">
      </el-table-column>
      <el-table-column
              prop="image"
              label="讲师头像" width="200px">
        <template slot-scope="scope">
          <img :src="scope.row.image" style="width: 100%" >
        </template>
      </el-table-column>
      <el-table-column
              prop="position"
              label="职位">
      </el-table-column>
      <el-table-column
              prop="motto"
              label="座右铭">
      </el-table-column>
      <el-table-column
              prop="intro"
              label="简介">
      </el-table-column>
      <el-table-column
              label="操作"
              width="120">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete" size="small" @click="del(scope.row.id)" circle></el-button>
        </template>
      </el-table-column>
    </el-table>

    <add-teacher
            :title="title"
            :dialogFormVisible="visible"
            :data="data"
            @val-change=""
            @cancel="visible = false"/>

  </div>
</template>

<script>
    import business from './../../../api/business';
    import ToolBar from '~/components/ToolBar/ToolBar.vue';
    import HelpHint from '~/components/HelpHint/HelpHint.vue';
    import AddTeacher from '~/views/ContentManage/teacher/AddTeacher.vue';

    const { teacherList } = business
    export default {
        data() {
            return {
                title: '添加教师',
                data: false,
                visible: false,
                page: {
                    total: 0
                },
                searchParams: {
                    page: 1,
                    size: 5,
                    name: 'published',
                },
                tableData: []
            }
        },
        created: function () {
            this.getList()
        },
        methods: {
            getList() {
                teacherList(this.searchParams).then((response) => {
                    this.tableData = response.data.data.records
                    this.page.total = response.data.data.total
                })
            },
            addTeacher() {
                this.visible = true
            },
            save(row) {
                console.log(row)
            }
        },
        components: {
            AddTeacher,
            ToolBar, HelpHint
        }
    }
</script>

<style lang="less">
  .demo {
    margin: 10px;

    .grid-content {
      border-radius: 4px;
      overflow: hidden;
      color: #fff;
      background: #d3dce6;

      .index-icon {
        font-size: 82px;
        color: #fff;
      }
    }
  }
</style>